import MonsterSkillVO from "../../../db/vo/MonsterSkillVO";
import { MonsterStateType } from "../../MonsterStateType";
import GlobalData from "../../../db/GlobalData";
import MonsterScript from "../../../component/MonsterScript";


export default class BaseMonsterSkill {

    _monsterSkillVO: MonsterSkillVO;

    _preExecTime: number;

    _isSkilling: boolean = false;

    _cd: number;

    _target: MonsterScript;

    _durationTime: number;

    _skillData: any;



    public init(target: MonsterScript, skillId) {
        this._target = target;
        this._monsterSkillVO = GlobalData.getData(GlobalData.MonsterSkillVO, skillId);
        if (target.monsterData.skillData) {
            this._skillData = target.monsterData.skillData[String(skillId)]
        }
        this.resetTime();
    }

    public canExec(): Boolean {
        if ((Laya.Browser.now() - this._preExecTime) > this._cd) {
            return true;
        }
        return false;
    }

    public resetTime() {
        if (this._monsterSkillVO.minCd === -1) {
            return;
        }
        this._cd = Math.random() * (this._monsterSkillVO.minCd + (this._monsterSkillVO.maxCd - this._monsterSkillVO.minCd));
        this._durationTime = Math.random() * (this._monsterSkillVO.minDuration + (this._monsterSkillVO.maxDuration - this._monsterSkillVO.minDuration));
        this._preExecTime = Laya.Browser.now() + Math.random() * this._cd;
    }



    public reset() {
        this.resetTime();
        this._isSkilling = false;
    }

    public destroy() {
        this._target = null;
        this._monsterSkillVO = null;
    }



}